<?php
namespace app\common\model\mysql;
use think\Model;

class User extends Model{
   /*
    * 自动写入时间
    */
   protected $autoWriteTimestamp = true;

    /*
     * 获取用户信息
     * @param $phoneNumber
     * @return array|bool|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
   public function getUserByPhoneNumber($phoneNumber){
       if(empty($phoneNumber)){
           return false;
       }
       $where = [
           'phone_number'=>$phoneNumber
       ];
       return $this->where($where)->find();
   }

    /*
     * 更新用户的token
     * @param $userId
     * @param $token
     */
   public function updateUserToken($userId,$token){
       $where = [
           'id'=>$userId
       ];
       $saveData['token'] = $token;
       $this->where($where)->save($saveData);
   }

    /*
     * 通过id获取用户的信息
     * @param $id
     * @return array|bool|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
   public function getUserId($id){
      $id = intval($id);
      if(!$id){
          return false;
      }
      return $this->find($id);
   }
    
}

